package com.dob.app;

import org.hibernate.SessionFactory;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.dob.dbo.hibernate.HibernateTemplateExample;
import com.dob.dbo.jdbc.RowMapperExample;
import com.dob.model.Employee;

public class HibernateTemplateTest {
	
public static void main(String args[]){
		
		
		AbstractApplicationContext context= new ClassPathXmlApplicationContext("spring.xml");
		context.registerShutdownHook();
		Employee emp1= new Employee();
		emp1.setEmpId(405141);
		emp1.setEmpName("Test Employee");
		HibernateTemplateExample example=(HibernateTemplateExample)context.getBean("hibernateTemplateExample");
		
		example.setSessionFactory((SessionFactory)context.getBean("sessionFactory"));
		example.saveEmployee(emp1);
		
		
//		DataSourceExample dsExample=(DataSourceExample)context.getBean("dataSourceExample");
//		dsExample.getEmployee();
		
//		JDBCTemplateExample jdbcTemplateExample=(JDBCTemplateExample)context.getBean("jdbcTemplateExample");
//		jdbcTemplateExample.getEmployeeCount();
//		jdbcTemplateExample.getEmployeeName(9876);
		
//		RowMapperExample rowMapperExample=(RowMapperExample)context.getBean("rowMapperExample");
//		System.out.println(rowMapperExample.getEmployee(98765).getEmpName());
//		System.out.println(rowMapperExample.getAllEmployee().size());
//		
//		CRUDUsingJDBCTemplate CRUDUsingJDBCTemplate=(CRUDUsingJDBCTemplate)context.getBean("CRUDUsingJDBCTemplate");
//		System.out.println("Before Insert: "+CRUDUsingJDBCTemplate.getAllEmployee().size());
//		Employee emp=CRUDUsingJDBCTemplate.getEmployee(1234);
//		CRUDUsingJDBCTemplate.insertEmployee(emp);
//		System.out.println("After Insert: "+CRUDUsingJDBCTemplate.getAllEmployee().size());
		
//		NamedParameterJDBCTemplateExample namedParameterJDBCTemplateExample=(NamedParameterJDBCTemplateExample)context.getBean("namedParameterJDBCTemplateExample");
//		System.out.println("Before Insert: "+namedParameterJDBCTemplateExample.getAllEmployee().size());
//		Employee emp=namedParameterJDBCTemplateExample.getEmployee(9876);
//		namedParameterJDBCTemplateExample.insertEmployeeUsingNamedParameter(emp);
//		System.out.println("After Insert: "+namedParameterJDBCTemplateExample.getAllEmployee().size());
		
	}

}
